<?php
// 设置时区
date_default_timezone_set("PRC");
include 'MMysql.php';
require_once 'errorhandle.php';
  
session_start();
$do = $_GET['do'] ? $_GET['do'] : 'share';
if($do == 'share'){
    $uid = empty($_SESSION['uid']) ? 0 : $_SESSION['uid'];
    $link = $_POST['url'];
    $mysql = new MMysql();
    if(!$uid && !empty($_SESSION['openid'])){
        $user_info = $mysql->where(['openid'=>$_SESSION['openid']])->select('user3');
        $uid = $user_info[0]['id'];
    }
    if($uid) {
        $where_['uid'] = $uid;
        $where_['share_url'] = '\''.$link.'\'';
        try{
        $share_info = $mysql->where($where_)->limit(1)->select('share_log');
        }catch(PDOException $e){
            exit();
        }
        if(empty($share_info)){
            $data['uid'] = $uid;
            $data['share_url'] = $link;
            $data['share_url_count'] = 1;
            $data['share_time'] = time();
            $mysql->insert('share_log',$data);
        }else{
            $update_data['share_url_count'] = $share_info[0]['share_url_count']+1;
            $update_data['repeat_share_time'] = time();
            $mysql->where($where_)->update('share_log',$update_data);
        }
    }else{
        $data['uid'] = $uid;
        $data['share_url'] = $link;
        $data['share_url_count'] = 1;
        $data['share_time'] = time();
        $mysql->insert('share_log',$data);
    }
}
